package com.lzw.security.controller;

import com.lzw.security.entity.*;
import com.lzw.security.exception.TidcNulException;
import com.lzw.security.ov.UserOV;
import com.lzw.security.service.CheckService;
import com.lzw.security.util.RedisUtil;
import com.lzw.security.util.SpringUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020-3-28 20:46
 * @description：获取和查看的请求控制器
 * @modified By：
 * @version:
 */
@RequestMapping("/check")
@RestController
@CrossOrigin(origins = "*",maxAge = 3600)
public class CheckController {
    @Autowired
    RedisUtil redisUtil;
    @Autowired
    private CheckService checkService;
    /**
     * create by: 冯涛滔
     * description: 获取首页固定的8个类型
     * create time: 2020-3-29 20:32
     * @params []
     * @return com.lzw.security.ov.UserOV<java.util.List < java.util.List < com.lzw.security.entity.Category>>>
     */
    @ApiOperation("获取首页的8个类型 不需要参数")
    @GetMapping("/index/category")
    public UserOV<List<List<Category>>> getIndexCategoryList(){
        return checkService.getIndexCategoryList();
    }
    /**
     * create by: 冯涛滔
     * description: 获取分类的列表
     * create time: 2020-3-28 20:50
     * @params []
     * @return com.lzw.security.ov.UserOV
     */
    @ApiOperation("获取所有的类型 不需要参数")
    @GetMapping("/category")
    public UserOV<List<List<Category>>> getCategoryList(){
        return checkService.getCategoryList();
    }
    @ApiOperation("获取所有的配料 不需要参数")
    @GetMapping("/dosing")
    public UserOV<List<Dosing>> getAllDosing(){
        return checkService.getAllDosing();
    }
    /**
     * create by: 冯涛滔
     * description: 查找某个分类下的商品列表
     * create time: 2020-3-29 11:52
     * @params [category] id && curPage && pageSize
     * @return com.lzw.security.ov.UserOV<java.util.List < com.lzw.security.entity.Commodity>>
     */
    @ApiOperation("按照类型获取商品列表只会显示上架的 必填 id 类型id curPage第几页 pageSize一页几条数据")
    @GetMapping("/category/commodity")
    public UserOV<Map<String,Object>> checkCommodityInCategory(@RequestParam("id") Integer id, @RequestParam("curPage") Integer curPage,
                                                @RequestParam("pageSize") Integer pageSize) throws TidcNulException {
        Category category = new Category();
        category.setId(id).setPageSize(pageSize).setCurPage(curPage);
        return checkService.checkCommodityInCategory(category);
    }
    @ApiOperation("按照类型获取商品列表后台接口全部显示 必填 id 类型id curPage第几页 pageSize一页几条数据")
    @GetMapping("/admin/category/commodity")
    public UserOV<Map<String,Object>> checkAdminCommodityInCategory(@RequestParam("id") Integer id, @RequestParam("curPage") Integer curPage,
                                                               @RequestParam("pageSize") Integer pageSize) throws TidcNulException {
        Category category = new Category();
        category.setId(id).setPageSize(pageSize).setCurPage(curPage);
        return checkService.checkAdminCommodityInCategory(category);
    }
    @ApiOperation("获取秒杀商品列表")
    @GetMapping("/seckill")
    public UserOV<List<Seckill>> getSeckillList(){
        return checkService.getSeckillList();
    }
    @ApiOperation("查找所有的附属品 不需要参数")
    @GetMapping("/accessory")
    public UserOV<List<Accessory>> getAccessoryAll(){
        return checkService.getAccessoryAll();
    }
    @ApiOperation("根据附属品id来查找附属品的详情连配料表一起返回")
    @GetMapping("/accessory/dosing")
    public UserOV<Accessory> getAccessoryDosing(@RequestParam("id") int id){
        return checkService.getAccessoryDosing(id);
    }
    @ApiOperation("返回所有的优惠卷")
    @GetMapping("/coupon")
    public UserOV<List<Coupon>> getCoupon(){
        return checkService.getCoupon();
    }
//    @ApiOperation("获取用户的购物车")
//    @GetMapping("/cart")
//    public UserOV<List<Cart>> getUserCartList(HttpServletRequest req){
//
//    }
    @ApiOperation("获取所有用户信息")
    @GetMapping("/user/all")
    public UserOV<List<User>> getUserAll(){
        return checkService.getUserAll();
    }

}
